﻿@using Common
@model List<Param_TemplateClassify>
<link href="https://cdn.staticfile.org/layui/2.7.6/css/layui.css" rel="stylesheet">
<link rel="stylesheet" href="/Content/layuiadmin/style/admin.css" media="all">

<div class="layui-fluid">
    <div class="layui-container">
        <div class="layui-row">
            <div class="layui-col-xs10 layui-col-xs-offset1">
                <form class="layui-form" lay-filter="form" style="margin-right:60px;" onsubmit="return false">
                    <div class="layui-form-item">
                        <label class="layui-form-label">父级分类</label>
                        <div class="layui-input-block">
                            <select name="ParentID" id="ParentID" required lay-verify="required">
                                <option value="0">根分类</option>
                                @foreach (var item in Model)
                                {
                                    <option value="@item.ClassifyID">@item.Cname</option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">模板分类名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="Cname" id="Cname" required lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">权重</label>
                        <div class="layui-input-block">
                            <select name="ParentID" id="Power" required lay-verify="required">
                                    <option value="1">1</option>
                                    <option value="2">2</option>
                                    <option value="3">3</option>
                                    <option value="4">4</option>
                                    <option value="5">5</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否启用</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="Show" id="Show" lay-skin="switch">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn sub" lay-submit lay-filter="formDemo">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="https://cdn.staticfile.org/layui/2.7.6/layui.js"></script>
<script>
    layui.config({
        base: '/Content/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'set']);
</script>

<script src="~/Scripts/jquery-3.3.1.min.js"></script>
<script src="~/Scripts/tools.js"></script>
<script>
    var data = {};
    //Demo
    $(function () {
        var form = layui.form;
        var upload = layui.upload;
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            , url: '' //上传接口
            , auto: false//是否自动上传
            , bindAction: "#VBHUJ"
            , multiple: false
            , size: 1000 //上传图片大小限制 KB
            , number: 1 //同时上传数量
            , accept: "images" //文件类型
            , acceptMime: 'image/*'
            , choose: function (obj) {
                //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
                obj.preview(function (index, file, result) {
                    //console.log(index); //得到文件索引
                    //console.log(file); //得到文件对象
                    //console.log(result); //得到文件base64编码，比如图片
                    $("#timg").unbind();
                    $("#timg").attr("src", result);

                    $("#timg").click(function () {
                        openimg(`${result}`);
                    })

                });
            }
            , done: function (res) {
            }
            , error: function () {
                //请求异常回调
            }
        });
        form.on('submit(form)', function () {
            var index = layer.load(1, { shade: [0.6, "#fff"] });
            data.Cname = $("#Cname").val();
            data.Show = $("#Show")[0].checked;
            data.ParentID = $("#ParentID").val();
            data.Sort = $("#Power").val();
            console.log(data);
            $.post(apiurl + "api/TemplateClassify/Add", data, function (res) {
                console.log(res);
                if (res.Code == 200) {
                    setTimeout(() => {
                        layer.close(index);
                        layer.msg("添加成功", { icon: 6, time: 1500 });
                        setTimeout(() => {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                            parent.location.reload();
                        }, 600)
                    }, 300);
                }
                else {
                    layer.msg("添加失败", { icon: 5, anim: 6, time: 1500 });
                }
            })
        });



    })

</script>